import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    icon: []
  },
  mutations: {
    setIcon(state, action) {
      state.icon = action.data
    },
    changFlagVuex(state, { index, flag }) {
      state.icon[index].my = !flag
    },
    reset(state, { oldIcon }) {
      state.icon = oldIcon
    }
  },
  actions: {
    init({ commit }) {
      axios.get('/init').then(res => {
        commit('setIcon', {
          data: res.data
        })
      })
    }
  },
  modules: {
  }
})
